#ifndef __PKMNONLINE_SERVER_H__
#define __PKMNONLINE_SERVER_H__
#include <stdio.h>
#ifndef WIN32_LEAN_AND_MEAN
#	define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include "clientinfo.h"
#include "client.h"

#pragma comment(lib, "ws2_32.lib")

#define MAX_CLIENTS 100

class CServer {
public:
	CServer(int nPort);
	~CServer();

	void Update();
	
private:
	void Accept();
	void Register(SOCKET nSock, const SOCKADDR_IN *pAddr);
	bool Receive(CLIENTINFO *pClient);
	bool Send(CLIENTINFO *pClient);
	void Terminate(CLIENTINFO *pClient);

	SOCKET			m_nSock;
	WSADATA			m_wsaData;
	SOCKADDR_IN		m_saAddr;
	CLIENTINFO    **m_pciList;

	fd_set m_fdSet;
	fd_set m_fdRead, m_fdWrite;
	SOCKET m_nHighestFd;
};

#endif /* __PKMNONLINE_SERVER_H__ */
